<?php
class subitem{
	public $text;
	public $link;

	public function __construct($text, $link){
		$this->text = $text;
		$this->link = $link;
	}
}

class mainitem{
	public $id;
	public $text;
	public $link;
	public $subitemlist;

	public function __construct($id, $text, $link){
		$this->id = $id;
		$this->text = $text;
		$this->link = $link;
		$this->subitemlist = null;
	}
}

class menu{
	public $menu;

	public function __construct(){
		$this->menu = null;
	}

	public function addItem($id, $text, $link, $parent){
		if($parent!=0){
			for($i=0; $i<count($this->menu); $i++){
				if($this->menu[$i]->id==$parent){
					$this->menu[$i]->subitemlist[] = new subitem($text, $link);
					break;
				}
			}
		}
		else{
			$this->menu[] = new mainitem($id, $text, $link);
		}
	}

	public function show(){
		print "<div id=\"nav\">\n";
		print "<ul>\n";
			print "<li>\n";
			print "<div class=\"logo\"><a href=\"http://www.marketingman.hu\" onmouseover=\"closeSub();\"><img src=\"public/img/nav-logo.png\" alt=\"MMGC Kft.\" />MMGC Kft.</a></div>";
			print "</li>\n";
		for($i=0; $i<count($this->menu); $i++){
			$cnt = count($this->menu[$i]->subitemlist);
			print "<li class=\"menu" . $i . " \">\n";
			if($cnt>0){
				print "<a href=\"".$this->menu[$i]->link."\" onMouseOver=\"openSub(this.nextSibling.nextSibling);\">".$this->menu[$i]->text;
				print "<img src=\"public/img/dda.gif\" alt=\"Almenük\"></a>\n";
				print "<ul>\n";
				for($j=0; $j<$cnt; $j++){
					print "<li><a href=\"".$this->menu[$i]->subitemlist[$j]->link."\">".$this->menu[$i]->subitemlist[$j]->text."</a></li>\n";
				}
				print "</ul>\n";
			}
			else{
				if ($this->menu[$i]->link == "index.php?url=tartalom/honlapkesz") {
					print "<a href=\"".$this->menu[$i]->link."\" onmouseover=\"closeSub();\">".$this->menu[$i]->text."</a>\n";
				} elseif ($this->menu[$i]->link == "index.php?url=tartalom/referencia") {
					print "<a href=\"".$this->menu[$i]->link."\" onmouseover=\"closeSub();\">".$this->menu[$i]->text."</a>\n";
				} else {
				print "<a href=\"".$this->menu[$i]->link."\">".$this->menu[$i]->text."</a>\n";
				}
			}
			print "</li>\n";
		}
		print "</ul>\n";
		print "</div>\n";
		
	}

	public function showSubs($which){
		for($i=0; $i<count($this->menu); $i++){
			if($this->menu[$i]->id==$which){
				$which = $i;
				break;
			}
		}
		$cnt = count($this->menu[$which]->subitemlist);
		if($cnt>0){
			print "<div id=\"box\" class=\"menu-box\">";
			print "<h3><a href=\"".$this->menu[$which]->link."\">".$this->menu[$which]->text."</a></h3>";
			print "<ul>";
			for($i=0; $i<$cnt; $i++){
				print "<li><a href=\"".$this->menu[$which]->subitemlist[$i]->link."\">".$this->menu[$which]->subitemlist[$i]->text."</a></li>";
			}
			print "</ul>";
			print "</div>";
			return true;
		}
		else{
			/*print "<ul>";
			for($i=0; $i<count($this->menu); $i++){
				print "<li><a href=\"".$this->menu[$i]->link."\">".$this->menu[$i]->text."</a></li>";
			}
			print "</ul>";*/
		}
	}
}
?>